﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Globalization;
using System.Reflection;
using Microsoft.Internal;
using System.ComponentModel.Composition.ReflectionModel;

namespace System.ComponentModel.Composition.AttributedModel
{
    internal class AttributedParameterImportDefinition : AttributedImportDefinition
    {
        private readonly ReflectionParameter _parameter;

        public AttributedParameterImportDefinition(AttributedComposablePartDefinition definition, ParameterInfo parameter)
            : this(definition, new ReflectionParameter(parameter))
        {
        }

        private AttributedParameterImportDefinition(AttributedComposablePartDefinition definition, ReflectionParameter parameter)
            : base(definition, parameter, parameter.UnderlyingParameter)
        {
            this._parameter = parameter;
        }

        public override bool IsRecomposable
        {
            // Currently only used for constructor parameters so it is always non-recomposable
            get { return false; }
        }

        public override bool IsPrerequisite
        {
            // Currently only used for constructor parameters so it is always a prerequisite
            get { return true; }
        }

        public override ImportingItem ToImportingItem()
        {
            return new ImportingParameter(this, this._parameter);
        }

        protected override string GetDisplayName()
        {
            return string.Format(
                CultureInfo.CurrentCulture,
                "{0} (Parameter=\"{1}\", ContractName=\"{2}\")",  // NOLOC
                this.Definition.Constructor.GetDisplayName(),
                this._parameter.Name,                
                this.ContractName);
        }
    }
}
